import {
    Component,
    trigger,
    state,
    style,
    transition,
    animate,
    keyframes
} from '@angular/core';

import { Router } from '@angular/router';
import { AuthService } from '../scheme/auth.service';

@Component({
    moduleId: module.id,
    selector: 'my-login-wraper',
    templateUrl: 'login.component.html',
    styleUrls: ['login.component.css'],
    animations:[
        trigger('sliderIn', [
            state('in',
                style({
                    opacity: 1,
                    transform: 'translateX(0)'
                })
            ),
            transition('void => *', [
                animate('0.35s ease-in-out', keyframes([
                    style({opacity: 0, transform: 'translateX(-50px)', offset: 0}),
                    style({opacity: .8, transform: 'translateX(20px)',  offset: 0.8}),
                    style({opacity: 1, transform: 'translateX(0)', offset: 1.0})
                ]))
            ])
        ])
    ]
})
export class LoginComponent {

    constructor(public authService: AuthService, public router: Router) {};

    validBirth:string

    login() {
        if(this.validBirth === this.authService.validUser){
            this.authService.login().subscribe(() => {
                if (this.authService.isLoggedIn) {
                    // Get the redirect URL from our auth service
                    // If no redirect has been set, use the default
                    let redirect = this.authService.redirectUrl || '/admin/bearing/list';
                    // Redirect the user
                    this.router.navigate([redirect]);
                }
            })
        }else{
            alert('您的验证码不正确')   
        }
    };

    logout() {
        this.authService.logout();
    };
}